//
//  myCommendModel.swift
//  OnceNectar
//
//  Created by Zhang Dream on 2018/6/24.
//  Copyright © 2018年 com.inwhoop. All rights reserved.
//

import Foundation
import MappingAce
import SwiftyJSON
struct myCommendModel:Mapping {
    
    var beRepliedUserId : String?
    var commentator :String?
    var commentatorID :String?
    var commentContent :String?
    var commentStatus :String?
    var ifLiked :String?
    var commentType :String?
    var id :String?
    var jointId :String?
    var likesCount :String?
    var statusName :String?
    var typeName :String?
    var unapprovedReason :String?
   
    var info:infoModel?
    
    var created :String?
    var beRepliedUser : AuthorModel?
    
    var commentUser :AuthorModel?
    
    var relatedComments:[myCommendModel]
    
    
}
//-"channel": {
//    "id": 1,
//    "name": "科普",
//    "ascription": "article"
//},

extension myCommendModel{
    mutating func initChannel(dic: [String:Any]) {
        info = infoModel(fromDic: dic)
    }
    
    mutating func initReplied(dic: [String:Any]) {
        beRepliedUser = AuthorModel(fromDic: dic)
        
    }
    mutating func initAuthor(dic: [String:Any]) {
        commentUser = AuthorModel(fromDic: dic)
        let json = JSON(dic)
        let dict = json["grade"].dictionary
        if dict != nil {
            commentUser?.initGrade(dic: dict!)
        }
    }
    mutating func initRelatedComments(arr: [JSON]) {
        
        var xlabers :[myCommendModel] = []
        for object in arr {
            
            let xmodel = myCommendModel(fromDic: object.dictionary! )
            
            xlabers.append(xmodel)
        }
        relatedComments = xlabers
    }
   
}
